package com.boarsoft.boar.soagov.face.biz;

import java.util.List;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.boarsoft.boar.soagov.entity.FaceImpl;
import com.boarsoft.boar.soagov.face.FaceImplBiz;
import com.boarsoft.common.Util;
import com.boarsoft.common.dao.PagedResult;
import com.boarsoft.hibernate.biz.SimpleBizImpl;

@Component("FaceImplBiz")
public class FaceImplBizImpl extends SimpleBizImpl implements FaceImplBiz {

	@Override
	@Transactional(readOnly = true)
	public PagedResult<FaceImpl> list(String faceId, String key, String orderBy, int pageNo, int pageSize) {
		StringBuilder sb = new StringBuilder();
		sb.append(" and faceId = '").append(faceId).append("'");
		if (Util.strIsNotEmpty(key)) {
			sb.append(" and impl like '%").append(key).append("%'");
		}
		int total = dao.getTotal(FaceImpl.class, sb.toString());
		if (Util.strIsNotEmpty(orderBy)) {
			sb.append(" order by ").append(orderBy);
		} else {
			sb.append(" order by impl");
		}
		List<FaceImpl> lt = dao.list(FaceImpl.class, sb.toString(), pageNo, pageSize);
		return new PagedResult<FaceImpl>(total, lt, pageNo, pageSize);
	}

	@Override
	@Transactional
	public void save(FaceImpl o) {
		System.out.print(o.getId());
		if (o.getId() == null) {
			dao.save(o);
		} else {
			dao.update(o);
		}

	}

	@Override
	@Transactional
	public void delete(String id) {
		dao.delete(FaceImpl.class, id);
	}

	@Override
	@Transactional(readOnly = true)
	public FaceImpl get(String id) {
		return (FaceImpl) dao.get(FaceImpl.class, id);
	}

}
